package com.spsoft.vatoutinv.controller.negativestream;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.spsoft.core.annotation.AnonymousAccess;
import com.spsoft.core.annotation.Log;
import com.spsoft.core.controller.BaseController;
import com.spsoft.core.enums.LogActionType;
import com.spsoft.core.enums.LogMenuEnum;
import com.spsoft.core.model.Result;
import com.spsoft.vatoutinv.model.dto.negativestream.*;
import com.spsoft.vatoutinv.model.vo.negativestream.NegativestreamCombineLockVo;
import com.spsoft.vatoutinv.model.vo.negativestream.NegativestreamDealVo;
import com.spsoft.vatoutinv.model.vo.negativestream.NegativestreamForViewVo;
import com.spsoft.vatoutinv.model.vo.negativestream.NegativestreamQueryVo;
import com.spsoft.vatoutinv.service.negativestream.NvatNegativestreamForVatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@Api(tags = {"负数流水管理 "})
@RestController
@RequestMapping("/negativestream")
@RequiredArgsConstructor
@Validated
@Slf4j
public class NvatNegativestreamController extends BaseController {
    public static final String LOG_MSG = "(负数流水管理控制层)";
    private final NvatNegativestreamForVatService nvatNegativestreamForVatService;


    @ApiOperation("主页面-分页查询")
    @AnonymousAccess(value = "/queryForPage", method = RequestMethod.POST, permissionCode = "")
    @Log(value = "查询负数流水管理列表", type = LogActionType.SELECT, menuName = LogMenuEnum.VMS_NEGA_INFO)
    public Result<IPage<NegativestreamQueryVo>> queryForPage(@RequestBody NegativestreamQueryPageDto pageDto) {
        log.info("{}查询负数流水管理列表入参：{}", LOG_MSG, JSONObject.toJSONString(pageDto));
        return nvatNegativestreamForVatService.queryForPage(pageDto);
    }

    /**
     * 引用流水表service，在流水表的mapper中根据rdid查询流水，返回结果为自定义负数流水管理vo
     * 配合处理按钮查询负数流水信息
     * 参数：rdid
     * 或者rdid的正负集合，一起查正负流水
     */
    @ApiOperation("根据rdid查询流水")
    @AnonymousAccess(value = "/queryByRdid", method = RequestMethod.POST, permissionCode = "")
    @Log(value = "根据rdid查询流水", type = LogActionType.SELECT, menuName = LogMenuEnum.VMS_NEGA_INFO)
    public Result<NegativestreamDealVo> queryByRdid(@RequestParam(value = "rdid", required = true) String rdid) {

        log.info("{}根据rdid查询流水入参：{}", LOG_MSG, JSONObject.toJSONString(rdid));

        return nvatNegativestreamForVatService.queryByRdid(rdid);
    }

    /**
     * 点击处理按钮，处理选择的负数流水管理表中数据，
     * 参数：
     * 处理类型
     * 操作说明
     * 处理人
     * 处理日期
     */
    @ApiOperation("处理")
    @AnonymousAccess(value = "/deal", method = RequestMethod.POST, permissionCode = "")
    @Log(value = "负数流水管理处理", type = LogActionType.UPDATE, menuName = LogMenuEnum.VMS_NEGA_INFO)
    public Result deal(@RequestBody NegativesDealDto params) {

        log.info("{}负数流水管理处理入参：{}", LOG_MSG, JSONObject.toJSONString(params));

        boolean flag = nvatNegativestreamForVatService.dealByRdid(params);
        if (flag) {
            return Result.OK_MSG("处理成功");
        } else {
            return Result.ERROR("处理失败");
        }
    }

    @ApiOperation("关注")
    @AnonymousAccess(value = "/focus", method = RequestMethod.POST, permissionCode = "")
    @Log(value = "负数流水管理关注", type = LogActionType.UPDATE, menuName = LogMenuEnum.VMS_NEGA_INFO)
    public Result focusUndeal(@RequestParam(value = "id") String id) {//参数可换

        log.info("{}关注负数流水管理表入参：{}", LOG_MSG, JSONObject.toJSONString(id));

        boolean flag = nvatNegativestreamForVatService.updateNeFocusByid(id);
        if (flag) {
            return Result.OK_MSG("关注成功");
        } else {
            return Result.ERROR("关注失败");
        }
    }

    /**
     * 查看已处理的流水
     * 参数： id和rdid
     * <p>
     * 根据选择rdid查询流水
     * 返回自定义的vo
     * <p>
     * 根据id查询负数流水管理表中数据
     * 也封装到这个自定义vo中
     *
     * @param params
     * @return
     */
    @ApiOperation("查看")
    @AnonymousAccess(value = "/view", method = RequestMethod.POST, permissionCode = "")
    @Log(value = "查看", type = LogActionType.SELECT, menuName = LogMenuEnum.VMS_NEGA_INFO)
    public Result<NegativestreamForViewVo> view(@RequestBody NegativeForViewDto params) {

        log.info("{}查看负数流水管理表入参：{}", LOG_MSG, JSONObject.toJSONString(params));
        return nvatNegativestreamForVatService.queryForView(params);
    }

    /**
     * 根据选择的id直接还原处理类型
     * 参数
     * <p>
     * id
     *
     * @param id
     * @return
     */
    @ApiOperation("释放已处理流水")
    @AnonymousAccess(value = "/release", method = RequestMethod.POST, permissionCode = "")
    @Log(value = "释放已处理流水", type = LogActionType.UPDATE, menuName = LogMenuEnum.VMS_NEGA_INFO)
    public Result release(@RequestBody NegativesCommonDealDto params) {
        log.info("{}释放已处理流水入参：{}", LOG_MSG, JSONObject.toJSONString(params));

        boolean flag = nvatNegativestreamForVatService.releaseByid(params);
        if (flag) {
            return Result.OK_MSG("已释放已处理流水");
        } else {

            return Result.ERROR("已处理流水释放失败");
        }
    }

    /**
     * 查询正数流水页面
     * 参数 ：
     * 交易日期起
     * 交易日期止
     * 业务编号
     * 投保单号
     * 分页数据
     * <p>
     * 返回vo根据页面自定义
     *
     * @param params
     * @return
     */
    @ApiOperation("已拆分合并负数流水匹配锁定查询")
    @AnonymousAccess(value = "/combineLockQuery", method = RequestMethod.POST, permissionCode = "")
    @Log(value = "已拆分合并负数流水匹配锁定查询", type = LogActionType.SELECT, menuName = LogMenuEnum.VMS_NEGA_INFO)
    public Result<IPage<NegativestreamCombineLockVo>> combineLockQuery(@RequestBody NegativestreamCombineLockQueryPageDto params) {//参数可换
        log.info("{}已拆分合并负数流水匹配锁定查询入参：{}", LOG_MSG, JSONObject.toJSONString(params));

        return nvatNegativestreamForVatService.queryCombineLock(params);
    }

    /**
     *合并流水确定按钮
     * @param params
     * @return
     */
    @ApiOperation("已拆分合并负数流水匹配锁定确定")
    @AnonymousAccess(value = "/combineLockConfirm", method = RequestMethod.POST, permissionCode = "")
    @Log(value = "已拆分合并负数流水匹配锁定确定", type = LogActionType.SELECT, menuName = LogMenuEnum.VMS_NEGA_INFO)
    public Result combineLockConfirm(@RequestBody NegativesDealDto params) {
        log.info("{}已拆分合并负数流水匹配锁定确定入参：{}", LOG_MSG, JSONObject.toJSONString(params));
        return nvatNegativestreamForVatService.dealCombineLockByRdid(params);
    }

}
